/** dute.web.js **/
ux.extend({
	ajax:function(params){
		if(params.data.method.indexOf("/")==0){
			params.url = params.data.method;
			params.data = JSON.parse(params.data.params);	
		}
		$.ajax(params);
	}
});

$(function(){
	
	$(document).on("click","*[data-key]", function(e) {
		if($(this).attr("data-key") && $(this).attr("data-val")){
			var dute = $(this).get(0).dute;
			if(dute){
				var data = dute.getData();
				if($(this).attr("data-val")=="false"){
					data[$(this).attr("data-key")] = false;
				}else{
					data[$(this).attr("data-key")] = $(this).attr("data-val");
				}
				dute.setData(data);
			}
		}
	});
	
	$(document).on("click","*[click]", function(e) {
		var windPage = window.getPage();
		var click = $(this).attr("click");
		var funcName = click.indexOf("(")<0?click:(click.substring(0,click.indexOf("(")));		
		if(click.indexOf("(")<0){
			if(windPage[funcName]){
				windPage[click]();
			}else if(window[funcName]){
				window[click]();
			}
		}else{
			if(windPage[funcName]){
				eval("windPage."+click);
			}else if(window[funcName]){
				eval(click);
			}
		}
	});
	
	
	$(document).on("click","navigator", function(e) {
		if(top && top.notNavigator){
			return false;
		}
		var url = $(this).attr("url");
		var openType = $(this).attr("open-type");
		if(openType=="navigateBack"){
			window.history.back();
		}else{
			if(openType=="redirect"){
				if(!url || url=="#")return;
				window.location.href=url;
			}else if(url){
				if(!url || url=="#")return;
				window.open(url);
			}
		} 
	});
	
});